package com.cdzy.controller;

import com.cdzy.common.ApiResponse;
import com.cdzy.pojo.Notice;
import com.cdzy.service.NoticeService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 通知表(Notice)表控制层
 *
 * @author makejava
 * @since 2025-04-01 10:04:21
 */
@RestController
@RequestMapping("/notice")
@CrossOrigin
public class NoticeController {
    /**
     * 服务对象
     */
    @Resource
    private NoticeService noticeService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseEntity<Notice> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.noticeService.queryById(id));
    }

    /**
     * 查询通知数据
     * @return
     */
    @GetMapping("/getNoticeList")
    public ApiResponse<?> getListNotice() {
        List<Notice> noticeList = noticeService.getNoticeList();
        return ApiResponse.success(noticeList);
    }



    /**
     * 新增数据
     *
     * @param notice 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<Notice> add(@RequestBody Notice notice) {
        return ResponseEntity.ok(this.noticeService.insert(notice));
    }

    /**
     * 编辑数据
     *
     * @param notice 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public ResponseEntity<Notice> edit(@RequestBody Notice notice) {
        return ResponseEntity.ok(this.noticeService.update(notice));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable  Integer id) {
        return ResponseEntity.ok(this.noticeService.deleteById(id));
    }

}

